<template>
	<view class="apps">
		<image :src="bgImg" mode="widthFix" class="bgcard"></image>
		<view class="flex fdc" style="margin-top: -540rpx;" v-if="item.state == 1 || item.state == 2">
			<view class="flex bgwhite mtb20 mlr30 ptb20 plr20 aic br15 fdc">
				<view class="flex ptb20">
					<uv-avatar src="https://ball.lifecloud.top/static/hz.png" size="20"></uv-avatar><text class="f14">新疆融合体育中心</text>
				</view>
				<view class="flex aic ptb20">
					<uv-avatar :src="item.user.avatar" size="20"></uv-avatar><text class="f14">「羽你相约」邀请您加入对局</text>
				</view>
			</view>
			<view class="flex mtb20 ptb20 aic bgwhite">
				<view class="f1 flex">
					<uv-avatar-group :urls="list" keyName="avatar" size="30" gap="0.3"></uv-avatar-group>
				</view>
				<view class="flex f13 black fweight6">{{max}}人局,已参与{{count}}人</view>
			</view>
			<view class="flex bgwhite mtb20 mlr20 ptb20 plr20 br15 fdc">
				<view class="flex ptb20 f13">
					对局明细
				</view>
				<view class="flex f13 c666 plr20 ptb20">
					<view class="f1">场地</view>
					<view class="f1">日期</view>
					<view class="f1">预约时间</view>
				</view>
				<view class="flex fdc f13 c666 plr20" v-for="(it,idx) in item.goods" :key="idx">
					<view class="ptb20 flex aic red">
						<view class="f1">{{it.stadium.name}}</view>
						<view class="f1">{{it.year}}-{{it.month}}-{{it.days}}</view>
						<view class="f1">{{parseInt(it.hour)}}:00-{{parseInt(it.hour)+1}}:00</view>
					</view>
				</view>
			</view>
			<view class="flex mlr20  aic">
				<view class="f1 flex jcc">
					<uv-button type="error" text="分享邀约他人" open-type="share"></uv-button>
				</view>
				<view class="f1 flex jcc">
					<uv-button  type="error" text="加入对局" @click="handleAdd"></uv-button>
				</view>
			</view>
			<view class="flex bgwhite mtb20 mlr20 ptb20 plr20 br15 fdc f13">
				<view class="fweight6 black ptb10">邀约提示:</view>
				<view class="flex" style="line-height: 20px;">
					分享邀约分普通会员4人局及至尊会员8人局，普通会员参与对局最多4人，至尊会员可以到8人，参与至尊会员8人局加入对局的必须是至尊会员，普通会员无法参与至尊会员发起的对局！
				</view>
			</view>
		</view>
		<view class="flex bgwhite aic jcc" v-else >
			<view class="f14 red ptb20 fweight6">邀约已结束</view>
			
		</view>
		<uv-modal ref="modal" title="会员升级提示" content='您不是至尊会员，不能参与至尊8人局' 
		:showCancelButton="true" cancelText="取消" confirmText="确认升级" 
		:asyncClose="true"  @confirm="goShop" @cancel="cancel"></uv-modal>
	</view>
</template>

<script>
	import { util } from '/common/util.js';
	import { timeFormat } from '@/uni_modules/uv-ui-tools/libs/function/index.js'
	let app;
	export default {
	  data() {
		return {
		  id:0,
		  bgImg:"https://ball.lifecloud.top/static/share.jpg",
		  item:{},
		  count:0,
		  list:[],
		  max:0,
		  titleList:[
		  			  '【紧急呼叫羽毛球搭子】融合体育球场，打羽毛球！缺人速来！',
		  			  '「羽」你相约,周末不宅，球场见！羽毛球局已组好，缺你不可！',
		  			  '「打球不积极，思想有问题！快来组队拯救我的球技」',
		  			  '谁「羽」争锋！融合体育球场，求虐～',
		  			  '「听说打羽毛球能瘦？快来一起验证真理！」'
		  ],
		}
	  },
	  onLoad(opt) {
		app = this;
		this.id = opt.id;
		this.getList();
		this.getyuyue();
	  },
	  onShareAppMessage() {
	  		  const rdn = Math.round(Math.random() * (5 - 1)) + 1;
	      return {
	  			title: this.titleList[rdn-1],
	  			path: '/pages/order/share?id='+this.id,
	  			imageUrl:'https://ball.lifecloud.top/static/m.jpg'
	  		  }
	  },
	  methods: {
		async getList(){
			const data = await util.request({
				url:'/order/detail',
				data:{id:this.id}
			});
			if(data.code == '200'){
				this.item = data.data;
				if(this.item.type =='1'){
					this.max=8;
				}else{
					this.max=4;
				}
			} 
		},
		async getyuyue(){
			const data = await util.request({
				url:'/subscribe/record',
				data:{id:this.id}
			})
			if(data.code == '200'){
				this.list = data.data;
				this.count = data.data.length ||0;
			}
		},
		async handleAdd(){
			const data = await util.request({
					url:"/mpwechat/userinfo",
				});
			if(data.code != 200){
				uni.navigateTo({
					url:"/pages/member/login"
				})
			}
			if(this.item.type==1 && data.group_id != 3){
				this.$refs.modal.open();
				return false;
			}
			const rlt = await util.request({
					url:"/subscribe/add",
					data:{id:this.id}
				});
			util.alert(rlt.msg);
			if(rlt.code == 200){
				setTimeout(function(){
					uni.navigateTo({
						url:"/pages/member/subscribe"
					});
				},1500)
			}
		},
		goShop(){
			this.$refs.modal.close();
			uni.navigateTo({
				url:"/pages/sale/goods?id=5"
			});
		},
		cancel(){
			this.$refs.modal.close();
		}
	  }
	}
</script>


<style scoped>
	.bgcard{width: 100%;height:750rpx;}
</style>